package com.sskj.award.ui.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bulong.rudeness.RudenessScreenHelper;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.sskj.award.R;
import com.sskj.award.R2;
import com.sskj.award.bean.KongTouBean;
import com.sskj.award.presenter.AirDropBillPresenter;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.adapter.BaseAdapter;
import com.sskj.lib.adapter.ViewHolder;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.util.NumberUtil;
import com.sskj.lib.util.TimeFormatUtil;

import java.util.Date;
import java.util.List;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/07/18
 */
@Route(path = RConfig.SUPER_SUPER_AIR_DROP_BILL)
public class AirDropBillActivity extends BaseActivity<AirDropBillPresenter> {
    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @Autowired
    String type;
    @BindView(R2.id.rvAir)
    RecyclerView rvAir;
    @BindView(R2.id.srlAir)
    SmartRefreshLayout srlAir;
    private int page = 1;
    private BaseAdapter<KongTouBean.DataBean> airAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.super_activity_air_dro_pbill;
    }

    @Override
    public AirDropBillPresenter getPresenter() {
        return new AirDropBillPresenter();
    }

    @Override
    public void initView() {
        ARouter.getInstance().inject(this);
        tvTitle.setText(App.INSTANCE.getString(R.string.super_bills));
        mPresenter.getBillData(type, String.valueOf(page));


        rvAir.setLayoutManager(new LinearLayoutManager(this));
        rvAir.addItemDecoration(new DividerLineItemDecoration(this)
                .setLeftPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 1))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.super_divi_split))
        );

        srlAir.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                page = 1;
                mPresenter.getBillData(type, String.valueOf(page));
            }
        });
        srlAir.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshLayout) {
                page = 1;
                mPresenter.getBillData(type, String.valueOf(page));
            }
        });
    }

    @Override
    public void initData() {

    }

    public void getBillDataSuccess(KongTouBean data) {
        if (data == null) {
            return;
        }
        List<KongTouBean.DataBean> data1 = data.getData();
        airAdapter = new BaseAdapter<KongTouBean.DataBean>(R.layout.airdrop_item, null, rvAir) {
            @Override
            public void bind(ViewHolder holder, KongTouBean.DataBean item) {
                holder.setText(R.id.tvDescribe1, NumberUtil.keepNoZero(NumberUtil.keep(item.getMoney(), 6)) + "USDT")
                        .setText(R.id.tvDescribe3, item.getCreated_at())
                        .setText(R.id.tvDescribe2, item.getMark());
            }
        };
        airAdapter.addData(data1);
    }

    public void onStopFresh() {
        if (srlAir != null) {
            srlAir.finishRefresh();
            srlAir.finishLoadMore();
        }
    }
}
